package com.qky.note.JuejinCalculator;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;

import java.math.BigDecimal;

public class Calculator {
    public static BigDecimal execute(String expression) {
        CharStream cs = CharStreams.fromString(expression);
        System.out.println(cs);
        ExpressionLexer lexer = new ExpressionLexer(cs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        System.out.println(22222);
        System.out.println(1111);
        System.out.println(tokens);
        ExpressionParser parser = new ExpressionParser(tokens);
        ExpressionParser.CalcContext context = parser.calc();
        BigDecimalCalculationVisitor visitor = new BigDecimalCalculationVisitor();
        return visitor.visit(context);
    }

    public static void main(String[] args) {
        System.out.println( Calculator.execute("1+2"));
    }
}